import 'package:app/store/index.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ThemeSettingPage extends StatefulWidget {
  const ThemeSettingPage({super.key});

  @override
  State<ThemeSettingPage> createState() => _ThemeSettingPageState();
}

class _ThemeSettingPageState extends State<ThemeSettingPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("主题模式"),
        ),
        body: Consumer<ThemeModel>(builder: (context, model, child) {
          return Column(
            children: [
              ListTile(
                title: const Text("是否跟随系统"),
                trailing: Switch(
                    value: model.themeMode == ThemeMode.system,
                    onChanged: (value) {
                      if (value) {
                        model.themeMode = ThemeMode.system;
                      } else {
                        model.themeMode = ThemeMode.light;
                      }
                    }),
              ),
              ListTile(
                title: const Text("深色模式"),
                trailing: model.themeMode == ThemeMode.dark
                    ? const Icon(Icons.check)
                    : null,
                onTap: () {
                  model.themeMode = ThemeMode.dark;
                },
              ),
              ListTile(
                title: const Text("浅色模式"),
                trailing: model.themeMode == ThemeMode.light
                    ? const Icon(Icons.check)
                    : null,
                onTap: () {
                  model.themeMode = ThemeMode.light;
                },
              )
            ],
          );
        }));
  }
}
